<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class User extends Admin_Controller
{
	private static $data = array();
	protected $models=['user_model'];
	public function __construct()
	{
		parent::__construct();
		
	}

	//加载页面
	public function index()
	{	    
	    $this->load->view('admin/user/list.html');
	}
	//公司用户
	public function company()
	{
	    $this->load->view('admin/user/companyUser.html');
	}
	//黑名单
	public function blackList()
	{
	    $this->load->view('admin/user/blackList.html');
	}
	//获取用户列表
    public function getList(){
        $search=$this->input->get('search');
        $page=$this->input->get('page');
        $limit=$this->input->get('limit');
        $page=$page-1;
        $where=['is_delete'=>0,'userFlag'=>3];
        if($search){
            $dbArray['like']=['realName'=>$search];
            $dbArray['or_like']=['nickName'=>$search];
        }else{
            $dbArray=[];
        }
        $dbArray['page']=['limit'=>$limit,'offset'=>$page*$limit];
        
        $count=$this->user_model->getWhere_num($where,$dbArray);
        $user=$this->user_model->getWhere($where,'*',$dbArray);
        foreach ($user as $key=>$val){
            $user[$key]['createTime']=format_time($val['createTime']);
        }
        
        if($user){
            show200_admin($user,$count);
        }else{
            show400_admin();
        }
    }
    //获取用户列表
    public function getCompanyUser(){
        $search=$this->input->get('search');
        $page=$this->input->get('page');
        $limit=$this->input->get('limit');
        $page=$page-1;
        $where=['is_delete'=>0,'userFlag>'=>0];
        if($search){
            $dbArray['like']=['realName'=>$search];
            $dbArray['or_like']=['nickName'=>$search];
        }else{
            $dbArray=[];
        }
        $dbArray['page']=['limit'=>$limit,'offset'=>$page*$limit];
        $where_in=['field'=>'userFlag','data'=>[1,2,4]];
        $count=$this->user_model->getWhere_num($where,$dbArray,$where_in);
        $user=$this->user_model->getWhere($where,'*',$dbArray,$where_in);
        foreach ($user as $key=>$val){
            $user[$key]['createTime']=format_time($val['createTime']);
        }
        
        if($user){
            show200_admin($user,$count);
        }else{
            show400_admin();
        }
    }
    //获取黑名单用户列表
    public function getBlackList(){
        $search=$this->input->get('search');
        $page=$this->input->get('page');
        $limit=$this->input->get('limit');
        $page=$page-1;
        $where=['is_delete'=>1];
        if($search){
            $dbArray['like']=['realName'=>$search];
            $dbArray['or_like']=['nickName'=>$search];
        }else{
            $dbArray=[];
        }
        $dbArray['page']=['limit'=>$limit,'offset'=>$page*$limit];
        $count=$this->user_model->getWhere_num($where,$dbArray);
        $user=$this->user_model->getWhere($where,'*',$dbArray);
        foreach ($user as $key=>$val){
            $user[$key]['createTime']=format_time($val['createTime']);
        }
        
        if($user){
            show200_admin($user,$count);
        }else{
            show400_admin();
        }
    }
    //用户信息
    public function add(){
        $this->load->view('admin/user/add.html');
    }
    //启用竞拍功能
    public function able(){
        $userId=$this->input->post('userId');
        $res=$this->user_model->updateWhere(['userId'=>$userId],['userFlag'=>2]);
        if($res){
            show200_admin([],'','操作成功');
        }else{
            show400_admin('操作失败');
        }
    }
    //启用竞拍功能
    public function disable(){
        $userId=$this->input->post('userId');
        $res=$this->user_model->updateWhere(['userId'=>$userId],['userFlag'=>4]);
        if($res){
            show200_admin([],'','操作成功');
        }else{
            show400_admin('操作失败');
        }
    }
    //删除
    public function del(){
        $userId=$this->input->post('userId');
        $res=$this->user_model->delWhere_logic(['userId'=>$userId]);
        if($res){
            show200_admin([],'','操作成功');
        }else{
            show400_admin('操作失败');
        }
    }
    //移出黑名单/添加至白名单
    public function whiteuser(){
        $userId=$this->input->post('userId');
        $res=$this->user_model->updateWhere(['userId'=>$userId],['is_delete'=>0]);
        if($res){
            show200_admin([],'','操作成功');
        }else{
            show400_admin('操作失败');
        }
    }
    
	
	
	
}
/* End of file Login.php */